/**上传文件*/
$("#file_upload").uploadifive({
			'buttonText' : '请选择',
			'height' : 30,
			'uploadScript' : 'upload/submit.do',
			//上传文件类型编码，具体可见 http://www.cnblogs.com/anllin/articles/1994485.html
			'fileType' : 'application',
			'width' : 120,
			'auto' : true,//设置选择文件后是否自动上传
			'removeCompleted' : false,
			'fileObjName' : 'file',
			'onUploadComplete' : function(file, data) {
				var data = eval("(" + data + ")");
				if (data.success) {
					alert(data.msg);
					$("input[name='sku_file_name']").val(data.result);
				} else {
					alert(data.msg);
				}
			}
});
/**添加产品*/
function addPro(){
	addStr = "<tr>";
	addStr += "<td>产品名称</td><td><input type='text' name='pro_name' class='easyui-validatebox textbox' data-options='required:true,missingMessage:'请输入产品名称'' ></td>";
	addStr += "<td>旧SKU码</td><td><input type='text' name='old_sku' class='easyui-validatebox textbox' data-options='required:true,missingMessage:'请输入旧SKU码''></td>";
	addStr += "<td>新SKU码</td><td><input type='text' name='new_sku' class='easyui-validatebox textbox' data-options='required:true,missingMessage:'请输入新SKU码''></td>";
	addStr += "</tr>";
	$("#add_pro").append(addStr);
}
/**撤销一条产品*/
function cancelPro(){
	$("#add_pro").find("tr").last ().remove();
}
/**添加物流信息*/
function addExp(){
	addStr = "<tr>";
	addStr += "<td>箱子</td><td><input type='text' class='easyui-validatebox textbox' data-options='required:true,missingMessage:'请输入内容''></td>";
	addStr += "<td>物流单号</td><td><input type='text'class='easyui-validatebox textbox' data-options='required:true,missingMessage:'请输入物流单号''></td>";
	addStr += "</tr>";
	$("#add_exp").append(addStr);
}
/**撤销一条物流信息*/
function cancelExp(){
	$("#add_exp").find("tr").last ().remove();
}

$("#change_sub_btn").click(function(){
	$("#change_order_form").form('submit', {    
		url:'customer/change_business/submit.do',   
	    onSubmit: function(){//发送前操作
	    	var isValid = $(this).form('validate');
			return isValid;	// 返回false终止表单提交
	    },    
	    success:function(data) {
	    	var data = eval('(' + data + ')');  
		        if(data.success == true){
		        	//subProducts(data.result);
		        	//subExps(data.result);
		        	$.messager.alert('提示','<strong><center>'+data.msg+'</center></strong>');
		        	$("#change_order_form :input").val('');
//		        	var pp = $('#tabs').tabs('getSelected');    
//		        	var tab = pp.panel('options').tab; 
//		        	tab.panel('refresh');
		        }else{    
		        	$.messager.alert('警告','<strong><center>'+data.msg+'</center></strong>');    
		        }
		        if($('#tabs').tabs('exists',"我的换标订单")==true){
		        	$("#my_order_datagrid").datagrid('reload');
					$("#my_order_datagrid").datagrid('uncheckAll');
		    	}
		     }  
	});  
});
/**提交产品信息*/
function subProducts(CH_NO){
	var saveDataAry=new Array();  
    $('#add_pro tr').each(function(){
    	var attTd = $(this).children();
    	var pro_name = $.trim(attTd.eq(0).text());
    	var pro_name_val = $.trim(attTd.eq(1).find("input").val());
    	var old_sku = $.trim(attTd.eq(2).text());
    	var old_sku_val = $.trim(attTd.eq(3).find("input").val());
    	var new_sku = $.trim(attTd.eq(4).text());
    	var new_sku_val = $.trim(attTd.eq(5).find("input").val());
    	if(pro_name_val!="" || old_sku_val!="" || new_sku_val!=""){
    		var data = {"order_no":CH_NO,pro_name:pro_name_val,old_sku:old_sku_val,new_sku:new_sku_val};
        	saveDataAry.push(data);
    	}
    });
    $.ajax({ 
        type:"POST", 
        url:'customer/change_business/pro/submit.do',
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(saveDataAry), 
        success:function(data){ 
        	var data = eval('(' + data + ')');  
        	if(data.success == true){
	        	return true;   
	        }else{    
	        	$.messager.alert('警告','<strong><center>'+data.msg+'</center></strong>');    
	        } 
        } 
     }); 
}
/**提交物流信息*/
function subExps(CH_NO){
	var saveDataAry=new Array();  
    $('#add_exp tr').each(function(){
    	var attTd = $(this).children();
    	var box_val = $.trim(attTd.eq(1).find("input").val());
    	var exp_val = $.trim(attTd.eq(3).find("input").val());
    	if(box_val!="" || exp_val!=""){
    		var data = {"order_no":CH_NO,"box":box_val,"exp_no":exp_val};
        	saveDataAry.push(data);
    	}
    });
    $.ajax({ 
        type:"POST", 
        url:'customer/change_business/exp/submit.do',  
        dataType:"json",      
        contentType:"application/json",               
        data:JSON.stringify(saveDataAry), 
        success:function(data){ 
        	var data = eval('(' + data + ')');
        	 if(data.success == true){
		        	return true;   
		        }else{    
		        	$.messager.alert('警告','<strong><center>'+data.msg+'</center></strong>');    
		        }    
        } 
    }); 
 }